package com.ruoyi.tb.lmt.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.TEquipmentLog;
import com.ruoyi.tb.lmt.domain.TbRepairplanlist;
import com.ruoyi.tb.lmt.domain.TbWheelDiameter;
import com.ruoyi.tb.lmt.domain.TbWorkcategory;
import com.ruoyi.tb.lmt.domain.bo.*;
import com.ruoyi.tb.lmt.domain.vo.*;
import com.ruoyi.tb.lmt.mapper.OilSampleDetectionMapper;
import com.ruoyi.tb.lmt.mapper.TbRepairplanlistMapper;
import com.ruoyi.tb.lmt.mapper.TbWheelDiameterMapper;
import com.ruoyi.tb.lmt.service.*;
import com.ruoyi.tb.lmt.service.scheduler.SchedulerTask;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.text.ParseException;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;

@SaIgnore
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/digitalTwins")
public class TbDigitalTwinsController {

    @Autowired
    private ITbRepairplanlistService iTbRepairplanlistService;

    @Autowired
    private ITbLmtrepairWorkdetailService iTbLmtrepairWorkdetailService;

    @Autowired
    private ITbLocomotiveService iTbLocomotiveService;

    @Autowired
    private ITbParkingService iTbParkingService;

    @Autowired
    private ITbStorageService iTbStorageService;


    @Autowired
    private IRfidDataService iRfidDataService;


    @Autowired
    private ITbFdxdetailService iTbFdxdetailService;


    @Autowired
    private ITbAcceptancedetailService iTbAcceptancedetailService;

    @Autowired
    private TbRepairplanlistMapper tbRepairplanlistMapper;

    @Autowired
    private ITbLmttypeService iTbLmttypeService;

    @Autowired
    private ITbMutualInspectionService iTbMutualInspectionService;

    @Autowired
    private ITbSpecialInspectionService iTbSpecialInspectionService;

    @Autowired
    private ITbAcceptanceService iTbAcceptanceService;

    //大机检修数据面板
    @GetMapping("/list")
    public TbDigitalPlanListVo list(String lmtType, String lmtNumber) {
        return iTbRepairplanlistService.selectDigitalPlanList(lmtType, lmtNumber);
    }

    //大机车型型号
    @GetMapping("/list/selectLmt")
    public TableDataInfo<TbDigitalLmtVo> selectDigitalLmt(String lmtNumber, PageQuery pageQuery) {
        return iTbLmtrepairWorkdetailService.selectDigitalLmt(lmtNumber, pageQuery);
    }

    //高价件接口
    @GetMapping("/list/selectEquipment")
    public TableDataInfo<EquipmentVo> selectEquipment(String lmtNumber, PageQuery pageQuery) {
        return iTbLmtrepairWorkdetailService.selectEquipment(lmtNumber, pageQuery);
    }

    //试验台数据
    @GetMapping("/list/selectDateList")
    public DigitalDateVo selectDate(String lmtNumber) {
        return iTbLmtrepairWorkdetailService.selectDate(lmtNumber);
    }

    //油样试验台数据
    @GetMapping("/list/selectOilList")
    public List<OilSampleDetectionVo> selectOilList(String lmtNumber) {
        return iTbLmtrepairWorkdetailService.selectOilList(lmtNumber);
    }

    //油样测试试验台数据
    @GetMapping("/list/selectDrDamperList")
    public List<DrDamperDataVo> selectDrDamperList(String lmtNumber) {
        return iTbLmtrepairWorkdetailService.selectDrDamperList(lmtNumber);
    }

    //根据车号查询信息
    @GetMapping("/list/selectLocomotive")
    public TbLocomotiveVo selectLocomotive(String lmtNumber) {
        return iTbLocomotiveService.selectLocomotive(lmtNumber);
    }

    //查询计划详情
    @GetMapping("/list/selectWorkdetail")
    public TbRepairplanlist selectWorkdetail(Long lmtRepairId) {
        return iTbLmtrepairWorkdetailService.selectPlanInfo(lmtRepairId);
    }

    @GetMapping("/list/selectWorkDetailData")
    public TbLmtrepairWorkdetailVo selectWorkDetailData(String equipmentName, Long lmtRepairId) {
        return iTbLmtrepairWorkdetailService.selectWorkDetailData(equipmentName, lmtRepairId);
    }

    //车位信息
    @GetMapping("/list/parking")
    public TableDataInfo<TbParkingVo> list(TbParkingBo bo, PageQuery pageQuery) {
        return iTbParkingService.queryPageList(bo, pageQuery);
    }

    //rfid信息
    @GetMapping("/list/rfid")
    public TableDataInfo<RfidDataVo> list(String rfidBzm, String fromIp, PageQuery pageQuery) {
        return iRfidDataService.selectRfidData(rfidBzm, fromIp, pageQuery);
    }

    //查询大机统计
    @GetMapping("/list/lmtData")
    public TbDigitalLmtDataVo list() {
        return iTbLmtrepairWorkdetailService.selectLmtData();
    }

    //查询出入库设备数量
    @GetMapping("/list/equipmentCount")
    public EquipmentCountVO selectEquipmentCount() {
        return iTbLmtrepairWorkdetailService.selectEquipmentCount();
    }

    //查询出入库详细信息
    @GetMapping("/list/selectStorage")
    public TableDataInfo<TbStorageVo> list(TbStorageBo bo, PageQuery pageQuery) {
        return iTbStorageService.queryPageList(bo, pageQuery);
    }


    //大机修程统计
    @GetMapping("/dailyStats")
    public ResponseEntity<List<Map<String, Object>>> getDailyStats(@RequestParam(value = "repairType", defaultValue = "") String repairType,
                                                                   @RequestParam(value = "startDate", defaultValue = "") String startDate,
                                                                   @RequestParam(value = "endDate", defaultValue = "") String endDate) {
        List<Map<String, Object>> stats = iTbRepairplanlistService.selectTypeList(repairType, startDate, endDate);
        return ResponseEntity.ok(stats);
    }

    //大机检修统计
    @GetMapping("/list/selectLmtRepair")
    public LocNumberVo selectLmtRepair(@RequestParam String startDate, @RequestParam String endDate) {
        return iTbRepairplanlistService.selectLmtRepair(startDate, endDate);
    }


    /**
     * 首页接口
     */


    //大机状态信息（检修中/全部）
    @GetMapping("/list/selectLocNumber")
    public LocNumberVo selectLocNumber() {
        return iTbLocomotiveService.selectLocNumber();
    }


//    @GetMapping("/getTaskStats")
//    public List<TaskStatsVo> getTaskStats(String startDate, String endDate) throws ParseException {
//
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        Date utilStartDate = StringUtils.isBlank(startDate) ? null : sdf.parse(startDate);  // 解析为 java.util.Date 对象
//
//        Date utilEndDate = StringUtils.isBlank(endDate) ? null : sdf.parse(endDate);  // 解析为 java.util.Date 对象
//
//        return iTbLmtrepairWorkdetailService.getTaskStats(utilStartDate, utilEndDate);
//    }

    /**
     * 首页当日任务完成度的折线图
     *
     * @param dataType
     * @return
     * @throws ParseException
     */
    @GetMapping("/getTaskStats")
    public List<TaskStatsVo> getTaskStats1(@RequestParam(value = "dataType", defaultValue = "1") String dataType) throws ParseException {
        Date endDate = new Date();
        Date startDate = new Date();
        LocalDate today = LocalDate.now();
        LocalDate previousDay = null;
        switch (dataType) {
            case "1":
                previousDay = today.minusDays(6);
                break;
            case "2":
                previousDay = today.minusDays(29);
                break;
        }
        startDate = Date.from(previousDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
        return iTbLmtrepairWorkdetailService.getTaskStats(startDate, endDate);
    }

    //定检/二级修检修动态
    @GetMapping("/list/selectTwoList")
    public RepairListCountVo selectTwoList(String repairStartDate, String repairEndDate) {
        return iTbRepairplanlistService.selectTwoList(repairStartDate, repairEndDate);
    }

    //年修/三级修检修动态
    @GetMapping("/list/selectThreeList")
    public RepairListCountVo selectThreeList(String repairStartDate, String repairEndDate) {
        return iTbRepairplanlistService.selectThreeList(repairStartDate, repairEndDate);
    }

    //架修/四级修检修动态
    @GetMapping("/list/selectFourList")
    public RepairListCountVo selectFourList(String repairStartDate, String repairEndDate) {
        return iTbRepairplanlistService.selectFourList(repairStartDate, repairEndDate);
    }


    //当前基地车辆数量
    @GetMapping("/list/selectCarNumber")
    public CarNumberVo selectCarNumber() {
        return iTbLocomotiveService.selectCarNumber();
    }

    /**
     * 强检到期车辆一览
     *
     * @param bo
     * @param pageQuery
     * @return
     */
    @GetMapping("/list/locomotive")
    public TableDataInfo<TbLocomotiveVo> listLocomotive(TbLocomotiveBo bo, PageQuery pageQuery) {
        return iTbLocomotiveService.listLocomotive(bo, pageQuery);
    }

    @PostMapping("/list/locomotive/export")
    public void export(TbLocomotiveBo bo, HttpServletResponse response) {
        List<TbLocomotiveVo> list = iTbLocomotiveService.listLocomotiveExport(bo);
        ExcelUtil.exportExcel(list, "大机配属", TbLocomotiveVo.class, response);
    }


    @GetMapping("/workdetail/info")
    public TbLmtrepairWorkdetailVo selectBy(String lmtType, String lmtNumber, String workCategory, String workCategoryId, String status) {
        TbLmtrepairWorkdetailVo vo = iTbLmtrepairWorkdetailService.selectByLmtTypeLmtNumberWorkCategoryWorkCategoryId(lmtType, lmtNumber, workCategory, workCategoryId, status);
        if (vo != null) {
            if (StringUtils.isBlank(vo.getWorkCategory())) {
                vo.setWorkCategory(vo.getWorkKind());
            }
        }
        return vo;
    }

    //架修数据的工作高
    @GetMapping("/list/work/height")
    public TableDataInfo<TbLmtrepairWorkdetailVo> workList(String workKind, String workCategory, String workName, String workRequire, String workGroup, PageQuery pageQuery) {
        return iTbLmtrepairWorkdetailService.selectWorkList1(null, workKind, workCategory, workName, workRequire, workGroup, null, pageQuery);
    }

    /**
     * 预检提报
     *
     * @param id
     * @param lmtType
     * @param lmtNumber
     * @param pageQuery
     * @return
     */
    @GetMapping("/list/unreported")
    public TableDataInfo<TbFdxdetailVo> selectUnreported(String id, String lmtType, String lmtNumber, PageQuery pageQuery) {
        return iTbFdxdetailService.selectUnreported(id, lmtType, lmtNumber, "已提报", pageQuery);
    }

    /**
     * 互检
     *
     * @param lmtType
     * @param lmtNumber
     * @param pageQuery
     * @return
     */
    @GetMapping("/list/selectMutualTask")
    public TableDataInfo<TbMutualInspectionVo> selectMutualTask(String lmtType, String lmtNumber, PageQuery pageQuery) {
        return iTbMutualInspectionService.selectByMutual(null, lmtType, lmtNumber, null, null, null, null, null, pageQuery);
    }

    /**
     * 专检
     *
     * @param lmtType
     * @param lmtNumber
     * @param pageQuery
     * @return
     */
    @GetMapping("/list/selectSpecialTask")
    public TableDataInfo<TbSpecialInspectionVo> selectSpecialTask(String lmtType, String lmtNumber, PageQuery pageQuery) {
        return iTbSpecialInspectionService.selectBySpecial(null, lmtType, lmtNumber, null, null, null, null, null, pageQuery);
    }

    /**
     * 验收
     *
     * @param lmtType
     * @param lmtNumber
     * @param pageQuery
     * @return
     */
    @GetMapping("/list/selectAcceptanceTask")
    public TableDataInfo<TbAcceptanceVo> selectAcceptanceTask(String lmtType, String lmtNumber, PageQuery pageQuery) {
        return iTbAcceptanceService.selectByAcceptance(null, lmtType, lmtNumber, null, null, null, null, null, pageQuery);
    }


    /**
     * 检修履历
     *
     * @param lmtType
     * @param lmtNumber
     * @param workerTeam
     * @param planCode
     * @param planName
     * @param repairChar
     * @param repairStartDate
     * @param repairEndDate
     * @param pageQuery
     * @return
     */
    @GetMapping("/list/historyLocomotive")
    public TableDataInfo<TbRepairplanlistVo> listHistoryLocomotive(String lmtType, String lmtNumber, String workerTeam, String planCode, String planName, String repairChar, String repairStartDate, String repairEndDate, PageQuery pageQuery) {
        return iTbRepairplanlistService.selectLocomotiveList1(lmtType, lmtNumber, workerTeam, planCode, planName, repairChar, repairStartDate, repairEndDate, "已完成", pageQuery);
    }


    /**
     * 轮径
     *
     * @param bo
     * @param pageQuery
     * @return
     */
    @GetMapping("/list/wheelDiameter")
    public TableDataInfo<TbLmtrepairWorkdetailVo> listWheelDiameter(TbLmtrepairWorkdetailBo bo, PageQuery pageQuery) {
        return iTbLmtrepairWorkdetailService.listWheelDiameter(bo, pageQuery);
    }


    @GetMapping("/locomotive/position/list1")
    public List<TbLocomotiveVo> Dlist(String lmtType, String lmtNumber) {
        TbLocomotiveBo bo = new TbLocomotiveBo();
        bo.setLmtType(lmtType);
        bo.setLmtNumber(lmtNumber);
        bo.setStatus("检修中");
        List<TbLocomotiveVo> list = iTbLocomotiveService.queryList(bo);
      /*  for (TbLocomotiveVo tbLocomotiveVo : list) {

            Long lmtRepairId = tbRepairplanlistMapper.selectLmtId(lmtType,lmtNumber);
            if (lmtRepairId != null) {
                TbRepairplanlist planList = tbRepairplanlistMapper.selectById(lmtRepairId);
                tbLocomotiveVo.setOverhaulProgress(planList.getStatus());
            }
        }*/
        return list;
    }


    @GetMapping("/locomotive/position/list")
    public List<TbParkingVo> positionList(String lmtType, String lmtNumber) {
        TbParkingBo bo = new TbParkingBo();
        bo.setLmtType(lmtType);
        bo.setLmtNumber(lmtNumber);
        return iTbParkingService.queryList1(bo);
    }

    @GetMapping("/locomotive/count")
    public Map<String, Object> LocomotiveCount() {
        Map<String, Object> params = new HashMap<>();
        params.put("locomotiveCount", iTbLocomotiveService.countAll());
        params.put("lmtTypeCount", iTbLmttypeService.countAll());
        return params;
    }

    /**
     * 停车
     *
     * @param day
     * @return
     */
    @GetMapping("/parking/count")
    public List<Map<String, Object>> parkingCount(Integer day) {
        if (day == null) {
            day = 7;
        }
        List<Map<String, Object>> result = new ArrayList<>();
        List<LocalDate> recentDays = getRecentDays(day);
        for (LocalDate recentDay : recentDays) {
            Map<String, Object> params = new HashMap<>();
            params.put("key", recentDay.toString().substring(recentDay.toString().indexOf("-") + 1, recentDay.toString().length()).replace("-", "/"));
            params.put("val", iTbParkingService.countByDay(recentDay));
            result.add(params);
        }
        return result;

    }

    @GetMapping("/completion/progress")
    public List<Map<String, Object>> completionProgress() {
        List<Map<String, Object>> result = new ArrayList<>();
        List<LocalDate> weeks = getNowMonthWeek();
        for (int i = 0; i < weeks.size(); i++) {
            Map<String, Object> params = new HashMap<>();
            params.put("key", "第 " + (i + 1) + " 周");
            params.put("two", iTbLmtrepairWorkdetailService.countByWeekAndWorkType(weeks.get(i), "二级修"));
            params.put("three", iTbLmtrepairWorkdetailService.countByWeekAndWorkType(weeks.get(i), "三级修"));
            params.put("four", iTbLmtrepairWorkdetailService.countByWeekAndWorkType(weeks.get(i), "四级修"));
            params.put("other", iTbLmtrepairWorkdetailService.countByWeekAndWorkType(weeks.get(i), "other"));
            result.add(params);
        }
        return result;
    }

    /**
     * 机检修统计列表
     *
     * @param repairType
     * @param
     * @param
     * @return
     */
    @GetMapping("/dailyStats/list")
    public ResponseEntity<Map<String, Object>> getDailyStats1(@RequestParam(value = "repairType", defaultValue = "") String repairType) {

        Map<String, Object> stats = iTbRepairplanlistService.selectTypeList1();
        return ResponseEntity.ok(stats);
    }

    /**
     * 大机统计
     *
     * @return
     */
    @GetMapping("/stat/list")
    public ResponseEntity<Map<String, Object>> getStats() {
        Map<String, Object> stats = iTbRepairplanlistService.getStats();
        return ResponseEntity.ok(stats);
    }

    public static List<LocalDate> getRecentDays(int days) {
        List<LocalDate> dates = new ArrayList<>();
        LocalDate currentDate = LocalDate.now();
        for (int i = 0; i < days; i++) {
            LocalDate date = currentDate.minusDays(i);
            dates.add(date);
        }
        Collections.reverse(dates);
        return dates;
    }

    public static List<LocalDate> getNowMonthWeek() {
        LocalDate today = LocalDate.now();
        LocalDate firstDayOfThisMonth = today.withDayOfMonth(1);
        List<LocalDate> weeks = new ArrayList<>();
        while (firstDayOfThisMonth.getMonthValue() == today.getMonthValue()) {
            DayOfWeek dayOfWeek = firstDayOfThisMonth.getDayOfWeek();
            LocalDate startOfWeek = firstDayOfThisMonth.minusDays(dayOfWeek.getValue() - 1);

            weeks.add(startOfWeek);

            firstDayOfThisMonth = firstDayOfThisMonth.plusWeeks(1);
        }
        return weeks;
    }


    @Autowired
    private ITbWorkcategoryService iTbWorkcategoryService;

    @GetMapping("/work/category/list")
    public R<List<TbWorkcategory>> treeBylmtType(@NotEmpty(message = "大机类型不能为空")
                                                 @RequestParam String lmtType) {
        return R.ok(iTbWorkcategoryService.treeBylmtType(lmtType));
    }

    @Autowired
    private SchedulerTask schedulerTask;
    @Autowired
    private TEquipmentLogService tEquipmentLogService;

    @GetMapping("/test")
    public void test(TEquipmentLog tEquipmentLog, PageQuery pageQuery) throws Exception {
         schedulerTask.test1();
    }

    /**
     * 轮径对比
     */
    @Autowired
    private TbWheelDiameterMapper tbWheelDiameterMapper;

    @GetMapping("/wheel/axle")
    public R<List<Map<String, Object>>> wheelAxle(@RequestParam("lmtNumber") String lmtNumber) {
        Map<String, Object> params = new HashMap<>();
        params.put("lmtNumber", lmtNumber);
        params.put("topNum", 1);
        List<TbWheelDiameter> tbWheelDiameters = tbWheelDiameterMapper.selectList(params);
        if (tbWheelDiameters != null && tbWheelDiameters.size() > 0) {
            List<WheelDiameterDataVo> wheelDiameterDataVoList = JsonUtils.parseArray(tbWheelDiameters.get(0).getJsonData(), WheelDiameterDataVo.class);
            List<Map<String, Object>> mapList = new ArrayList<>();
            for (int i = 0; i < wheelDiameterDataVoList.size(); i++) {
                Map<String, Object> param = new HashMap<>();
                param.put("label", (i + 1) + "轴");
                param.put("val", (i + 1));
                mapList.add(param);
            }
            return R.ok(mapList);
        }
        return R.fail("当前大机没有轮径信息");
    }

    @GetMapping("/wheel/diameter11")
    public R<List<Map<String, Object>>> wheelDiameter11(@RequestParam(value = "lmtNumber", defaultValue = "") String lmtNumber,
                                                        @RequestParam(value = "num", defaultValue = "7") int num) {
        Map<String, Object> params = new HashMap<>();
        params.put("lmtNumber", lmtNumber);
        params.put("topNum", num);
        List<TbWheelDiameter> tbWheelDiameters = tbWheelDiameterMapper.selectList(params);
        List<Map<String, Object>> list = new ArrayList<>();
        for (TbWheelDiameter tbWheelDiameter : tbWheelDiameters) {
            Map<String, Object> param = new HashMap<>();
            param.put("time", DateFormatUtils.format(tbWheelDiameter.getEndTime(), "yyyy/MM/dd"));
            List<WheelDiameterDataVo> ents = JsonUtils.parseArray(tbWheelDiameter.getJsonData(), WheelDiameterDataVo.class);
            List<String> names = new ArrayList<>();
            List<String> datas = new ArrayList<>();
            for (WheelDiameterDataVo ent : ents) {
                names.add(ent.getLeft1Name().replace("轮径", ""));
                names.add(ent.getLeft2Name().replace("轮径", ""));
                names.add(ent.getRight1Name().replace("轮径", ""));
                names.add(ent.getRight2Name().replace("轮径", ""));
                param.put("names", names);
                datas.add(ent.getLeft1Val());
                datas.add(ent.getLeft2Val());
                datas.add(ent.getRight1Val());
                datas.add(ent.getRight2Val());
                param.put("datas", datas);
            }
            list.add(param);
        }

        return R.ok(list);
    }


    @GetMapping("/wheel/diameter")
    public R<Map<String, Object>> wheelDiameter111(@RequestParam(value = "lmtNumber", defaultValue = "") String lmtNumber,
                                                   @RequestParam(value = "num", defaultValue = "5") int num) {
        Map<String, Object> params = new HashMap<>();
        params.put("lmtNumber", lmtNumber);
        params.put("topNum", num);
        List<TbWheelDiameter> tbWheelDiameters = tbWheelDiameterMapper.selectList(params);
        Map<String, Object> result = new HashMap<>();
        List<String> label = new ArrayList<>();
        if (tbWheelDiameters != null && tbWheelDiameters.size() > 0) {
            TbWheelDiameter lun1 = tbWheelDiameters.get(0);
            List<WheelDiameterDataVo> wheelDiameterDataVoList = JsonUtils.parseArray(lun1.getJsonData(), WheelDiameterDataVo.class);
            for (WheelDiameterDataVo wheelDiameterDataVo : wheelDiameterDataVoList) {
                label.add(wheelDiameterDataVo.getLeft1Name());
                label.add(wheelDiameterDataVo.getLeft2Name());
                label.add(wheelDiameterDataVo.getRight1Name());
                label.add(wheelDiameterDataVo.getRight2Name());
            }
        }
        result.put("label", label);
        List<Map<String,Object>> vals = new ArrayList<>();
        for (TbWheelDiameter tbWheelDiameter : tbWheelDiameters) {
            Map<String, Object> param = new HashMap<>();
            param.put("name",DateUtils.parseDateToStr("yyyy/MM/dd",tbWheelDiameter.getEndTime()));
            List<WheelDiameterDataVo> wheelDiameterDataVoList = JsonUtils.parseArray(tbWheelDiameter.getJsonData(), WheelDiameterDataVo.class);
            List<String> val = new ArrayList<>();
            for (WheelDiameterDataVo vo : wheelDiameterDataVoList) {
                val.add(vo.getLeft1Val());
                val.add(vo.getLeft2Val());
                val.add(vo.getRight1Val());
                val.add(vo.getRight2Val());
            }
            param.put("val",val);
            vals.add(param);
        }
        result.put("vals", vals);
        return R.ok(result);
    }

    @GetMapping("/locomotive/due/list")
    public TableDataInfo<TbLocomotiveVo> list(TbLocomotiveBo bo, PageQuery pageQuery) {
        return iTbLocomotiveService.getDue(bo, pageQuery);
    }

    /**
     * 油样对比
     *
     * @param lmtNumber
     * @param num
     * @return
     */
    @Autowired
    private OilSampleDetectionMapper oilSampleDetectionMapper;

    @GetMapping("/oil/sample")
    public R<Map<String, Object>> wheelDiameter(@RequestParam("lmtNumber") String lmtNumber,
                                                @RequestParam(value = "type", defaultValue = "") String type) {
        Map<String, Object> param = new HashMap<>();
        param.put("lmtNumber", lmtNumber);
        param.put("topNum", 5);
        param.put("type", type);
        List<OilSampleDetectionVo> oilSampleDetectionVos = oilSampleDetectionMapper.selectOilByMap(param);
        Map<String, Object> params = new HashMap<>();
        List<String> label = new ArrayList<>();
        Map<String, Object> val1 = new HashMap<>();
        Map<String, Object> val2 = new HashMap<>();
        Map<String, Object> val3 = new HashMap<>();
        Map<String, Object> val4 = new HashMap<>();
        Map<String, Object> val5 = new HashMap<>();
        label.add("Fe");
        label.add("Cr");
        label.add("Pb");
        label.add("Cu");
        label.add("Sn");
        label.add("Al");
        label.add("Ni");
        label.add("Ag");
        label.add("Si");
        label.add("B");
        label.add("Na");
        label.add("Mg");
        label.add("Ca");
        label.add("Ba");
        label.add("P");
        label.add("Zn");
        label.add("Mo");
        label.add("Ti");
        label.add("V");
        label.add("Mn");
        label.add("Cd");
        label.add("H");
        label.add("C");

        params.put("label", label);
        params.put("val1", val1);
        params.put("val2", val2);
        params.put("val3", val3);
        params.put("val4", val4);
        params.put("val5", val5);
        for (int i = 0; i < 5; i++) {
            Map<String, Object> val = (Map<String, Object>) params.get("val" + (i + 1));
            List<Double> vall = new ArrayList<>();
            if (i < oilSampleDetectionVos.size()) {
                OilSampleDetectionVo vo = oilSampleDetectionVos.get(i);
                vall.add(Double.parseDouble(vo.getOilFe()));
                vall.add(Double.parseDouble(vo.getOilCr()));
                vall.add(Double.parseDouble(vo.getOilPb()));
                vall.add(Double.parseDouble(vo.getOilCa()));
                vall.add(Double.parseDouble(vo.getOilSn()));
                vall.add(Double.parseDouble(vo.getOilAl()));
                vall.add(Double.parseDouble(vo.getOilNi()));
                vall.add(Double.parseDouble(vo.getOilAg()));
                vall.add(Double.parseDouble(vo.getOilSi()));
                vall.add(Double.parseDouble(vo.getOilB()));
                vall.add(Double.parseDouble(vo.getOilNa()));
                vall.add(Double.parseDouble(vo.getOilMg()));
                vall.add(Double.parseDouble(vo.getOilCa()));
                vall.add(Double.parseDouble(vo.getOilBa()));
                vall.add(Double.parseDouble(vo.getOilP()));
                vall.add(Double.parseDouble(vo.getOilZn()));
                vall.add(Double.parseDouble(vo.getOilMo()));
                vall.add(Double.parseDouble(vo.getOilTi()));
                vall.add(Double.parseDouble(vo.getOilV()));
                vall.add(Double.parseDouble(vo.getOilMn()));
                vall.add(Double.parseDouble(vo.getOilCd()));
                vall.add(Double.parseDouble(vo.getOilH()) / 1000);
                vall.add(Double.parseDouble(vo.getOilC()) / 1000);
                val.put("name", DateUtils.parseDateToStr("yyyy/MM/dd", DateUtils.dateTime("dd/MM/yyyy", vo.getOilData())));
            } else {
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                vall.add(0.0);
                val.put("name", "暂无");
            }
            val.put("val", vall);
        }


        return R.ok(params);
    }
}
